The Magical It and Them Tiles
The it and them tiles are ideas I have only seen in Spark, and they try to make your kode look more natural as you write it. However, it is important to understand what information they will contain, because if you haven't set up the when side of your kode correctly, they may not contain any information at all. The It Tile The it tile looks at the when side of its line to see if it evaluates to either a single object or an object set. If so, then it refers to the object or the first object in the set. If an object or object set is not found, each parent rule is checked, starting with the nearest one, until either the value of it can be set, or there are no more parent lines to check. Another interesting use of the it tile is in a each of loop. If you loop over an object set, then you can use the it tile to refer to the current object. The Them Tile The them tile works similarly to the it tile, except it treats what is found as an object set. Some Uses One of the most common ways to use the it tile is to check if an object exists in your when section, then to do something. This line checks to see if you have an object defined as Enemy, and if you do, shoots at it. Another very common way of using both the it and them tiles are with sensors. Lets look at this line: This could be for something like a fire zone your character puts on the ground. The them tile is referring to the enemies found in the trigger zone. You could use it in place of them above, which would choose just one enemy out of the set. You could also be looking for a specific object to enter the trigger zone instead like this. Note: global player is an object variable that has been defined, and not the custom player tile. Common Mistakes Please note an easy mistake to make here: Checking if your object set has a count greater than 0, or that your object variable is not equal to nothing will *not* set your it tile. Let's take a quick look at why. The When side above is evaluating to a boolean. It is either true or false, and therefore is *not* going to set the it tile, so the object will never jump. However, we can update the kode to be: This will work, because the when side evaluates to the object variable and so the it tile is set. This is the same as the object set example. The use of than changes the result of the expression into a boolean rather than an object set, which doesn't allow the them tile to function. Therefore the above kode will NOT work as intended. Instead, you need this kode: If the enemies object set is nonempty, them will be set to that object set and therefore the nearest object inside them will be displayed correctly. Small correction Even though it may look like it, the it and them tiles don't work as described in the first two sections. You can find a thorough explanation of how they are actually set in this topic: Undefined variable and it/them behaviour. =Read Next= Tiles That Reset =Further Reading= Timing and Logic Brain Tiles < Back to Koding Curriculum Category:Brains